<template>
  <div>
    <FormPanel
      ref="formPanel"
      :list="formList"
      :formType="type"
      @formChange="formChangeHandle"
      :isSubmitBtn="false"
      :collapse="false"
      labelWidth="130"
    />
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'center'
      }"
    >
      <multiuse-button
        type="primary"
        v-show="type != 'show'"
        :click="saveHandle.bind(this, 60211001)"
      >保 存</multiuse-button>
      <multiuse-button
        type="primary"
        v-show="type != 'show'"
        :click="saveHandle.bind(this, 60211002)"
      >提 交</multiuse-button>
      <el-button @click="closeDrawer">关 闭</el-button>
    </div>

    <BaseDialog
      :visible.sync="isDealer"
      title="经销商清单"
      destroyOnClose
      :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }"
    >
      <SearchDealer :rowData="formData" @close="emitCloseHandler1" />
    </BaseDialog>
  </div>
</template>
<script>
import moment from 'moment';
import { getAppId } from '@/assets/js/auth';
import { dictionary } from '@/utils/dictMixin';
import { getUser } from '@/assets/js/auth';
import { detailInfo, saveData, getAmount } from '@/api/omFinance/RebateRedInvoice/RebateRedInvoiceApply';
import SearchDealer from './SearchDealer';
import { isArcfox } from '@/api/cms-api/origin/commonDealerType';

export default {
  name: 'SonModel',
  mixins: [dictionary],

  props: ['type', 'rowData'],
  components: {
    SearchDealer
  },
  data() {
    this.saveData = null;
    return {
      formList: this.createdFrom(),
      formData: {},
      isDealer: false,
      taxRate1: 0,
      Amount1: 0,
      taxRate2: 0,
      Amount2: 0,
      taxRate1D: 0,
      Amount1D: 0,
      taxRate2D: 0,
      Amount2D: 0,
      totalApplyAmountR: 0,
      totalApplyAmountDR: 0,
      includeTaxAmountTax: 0
    };
  },

  mounted() {
    if (getAppId() == 'beijing') {
      if (this.formList.find(x => x.fieldName == 'powerType') == 60081001) {
        this.formList.find(x => x.fieldName == 'rebateType').itemList = this.createDictList('6036', [60361002]);
        this.formList.find(x => x.fieldName == 'rebateTypeD').itemList = this.createDictList('6036', [60361002]);
      }
    }
    this.init();
  },
  created() {
    if (isArcfox()) {
      this.formList.find(x => x.fieldName == 'powerType').disabled = true;
      this.formList.find(x => x.fieldName == 'salesOrgCode').itemList = [{ text: '北京蓝谷极狐投资管理有限公司销售组织', value: '1012' }];
    } else {
      this.formList.find(x => x.fieldName == 'powerType').disabled = false;
      this.getSalesOrgCode(this.rowData.powerType);
    }
  },
  computed: {
    taxAmount1: function() {
      // 税率
      let taxRate1 = parseFloat(this.taxRate1) || 0;
      // 金额1（含税）
      let Amount1 = parseFloat(this.Amount1) || 0;
      // 税额 = 金额1（含税）/（1+税率）*税率
      let taxAmount1 = (((Amount1 / ((100 + taxRate1) / 100)) * taxRate1) / 100).toFixed(2);
      this.formList.find(x => x.fieldName == 'taxAmount1').initialValue = parseFloat(taxAmount1);
      // 不含税金额 = 金额1（含税）-税额1
      this.formList.find(x => x.fieldName == 'outcluedeTaxAmount1').initialValue = parseFloat(Amount1 - taxAmount1).toFixed(2) || 0;
    },
    taxAmount2: function() {
      // 税率
      let taxRate2 = parseFloat(this.taxRate2) || 0;
      // 金额2（含税）
      let Amount2 = parseFloat(this.Amount2) || 0;
      // 税额 = 金额1（含税）/（2+税率）*税率
      let taxAmount2 = (((Amount2 / ((100 + taxRate2) / 100)) * taxRate2) / 100).toFixed(2);
      this.formList.find(x => x.fieldName == 'taxAmount2').initialValue = parseFloat(taxAmount2);
      // 不含税金额 = 金额1（含税）-税额1
      this.formList.find(x => x.fieldName == 'outcluedeTaxAmount2').initialValue = parseFloat(Amount2 - taxAmount2).toFixed(2) || 0;
    },
    taxAmount1D: function() {
      // 税率
      let taxRate1D = parseFloat(this.taxRate1D) || 0;
      // 金额1（含税）
      let Amount1D = parseFloat(this.Amount1D) || 0;
      // 税额 = 金额1（含税）/（1+税率）*税率
      console.log(Amount1D);
      let taxAmount1D = (((Amount1D / ((100 + taxRate1D) / 100)) * taxRate1D) / 100).toFixed(2);
      this.formList.find(x => x.fieldName == 'taxAmount1D').initialValue = parseFloat(taxAmount1D);
      // 不含税金额 = 金额1（含税）-税额1
      this.formList.find(x => x.fieldName == 'outcluedeTaxAmount1D').initialValue = parseFloat(Amount1D - taxAmount1D).toFixed(2) || 0;
    },
    taxAmount2D: function() {
      // 税率
      let taxRate2D = parseFloat(this.taxRate2D) || 0;
      // 金额2（含税）
      let Amount2D = parseFloat(this.Amount2D) || 0;
      // 税额 = 金额1（含税）/（2+税率）*税率

      let taxAmount2D = (((Amount2D / ((100 + taxRate2D) / 100)) * taxRate2D) / 100).toFixed(2);
      this.formList.find(x => x.fieldName == 'taxAmount2D').initialValue = parseFloat(taxAmount2D);
      // 不含税金额 = 金额1（含税）-税额1
      this.formList.find(x => x.fieldName == 'outcluedeTaxAmount2D').initialValue = parseFloat(Amount2D - taxAmount2D).toFixed(2) || 0;
    }
  },
  methods: {
    init() {
      if (this.type != 'add') {
        this.getInfoById();
      }

      if (this.type == 'show') {
        this.formList.find(x => x.fieldName == 'rebateType').itemList = this.createDictList('6036');
        this.formList.map(x => {
          if (x.rules) {
            x.rules[0].required = false;
          }
        });
      }
    },
    // 详细
    async getInfoById() {
      const res = await detailInfo(this.rowData.id);
      if (res.resultCode == 200) {
        this.formList.map(x => {
          x.initialValue = res.data[x.fieldName];
        });
        let array = [];
        array.push(this.formList.find(x => x.fieldName == 'rebateType').initialValue);
        if (getAppId() == 'beijing') {
          array.push(60361002);
        }
        this.formList.find(x => x.fieldName == 'rebateTypeD').disabled = true;
        this.formList.find(x => x.fieldName == 'rebateType').disabled = true;
        this.formList.find(x => x.fieldName == 'rebateTypeD').itemList = this.createDictList('6036', array);
        this.Amount1 = this.formList.find(x => x.fieldName == 'includeTaxAmount1').initialValue;
        this.Amount2 = this.formList.find(x => x.fieldName == 'includeTaxAmount2').initialValue;
        this.Amount1D = this.formList.find(x => x.fieldName == 'includeTaxAmount1D').initialValue;
        this.Amount2D = this.formList.find(x => x.fieldName == 'includeTaxAmount2D').initialValue;
        this.totalApplyAmountR = this.formList.find(x => x.fieldName == 'totalApplyAmount').initialValue;
        this.totalApplyAmountDR = this.formList.find(x => x.fieldName == 'totalApplyAmountD').initialValue;
        let array1 = [];
        array1.push(this.formList.find(x => x.fieldName == 'rebateTypeD').initialValue);
        if (getAppId() == 'beijing') {
          array1.push(60361002);
        }
        this.formList.find(x => x.fieldName == 'rebateType').itemList = this.createDictList('6036', array1);
        this.getAmount(this.rowData.powerType, this.rowData.rebateType, this.rowData.dealerCode);
        this.getAmountD(this.rowData.powerType, this.rowData.rebateTypeD, this.rowData.dealerCode);
      }
    },
    emitCloseHandler1(val, data) {
      this.isDealer = val;
      if (data) {
        this.formList.find(x => x.fieldName == 'dealerCode').initialValue = data[0].dealerCode;
        this.formList.find(x => x.fieldName == 'dealerName').initialValue = data[0].dealerName;
        let dealerCode = data[0].dealerCode;
        let rebateType = this.formList.find(x => x.fieldName == 'rebateType').initialValue;
        let powerType = this.formList.find(x => x.fieldName == 'powerType').initialValue;
        this.getAmount(powerType, rebateType, dealerCode);
        let rebateTypeD = this.formList.find(x => x.fieldName == 'rebateTypeD').initialValue;
        this.getAmountD(powerType, rebateTypeD, dealerCode);
      }
    },
    dealerHandle() {
      console.log('---经销商---');
      this.isDealer = true;
    },
    getSalesOrgCode(powerType = 60081002) {
      console.log('powerType===', powerType);
      this.formList.find(x => x.fieldName == 'salesOrgCode').initialValue = '';
      if (powerType == 60081002) {
        this.formList.find(x => x.fieldName == 'salesOrgCode').itemList = [
          { text: '北京新能源汽车营销有限公司', value: '2000' },
          { text: '青岛卫蓝销售公司', value: '2001' }
        ];
      } else {
        this.formList.find(x => x.fieldName == 'salesOrgCode').itemList = [
          { text: '北京汽车销售有限公司', value: '1080' },
          { text: '株洲北汽汽车销售有限公司', value: '1180' }
        ];
      }
    },
    emitcloseHandler() {},
    formChangeHandle(val) {
      this.saveData = val;
    },
    async saveHandle(type) {
      this.$refs.formPanel.SUBMIT_FORM();
      if (this.saveData !== null) {
        this.saveData.applyStatus = type;
        let json = JSON.parse(JSON.stringify(this.saveData));
        if (this.rowData.id) {
          json.id = this.rowData.id;
          if (json.totalApplyAmount > json.totalAmount + this.totalApplyAmountR) {
            this.$notify({
              title: '警告',
              message: '总申请金额不能大于返利可用余额',
              type: 'warning'
            });
            return;
          }
        } else {
          if (json.totalApplyAmount > json.totalAmount) {
            this.$notify({
              title: '警告',
              message: '总申请金额不能大于返利可用余额',
              type: 'warning'
            });
            return;
          }
        }
        if (json.includeTaxAmount2 === undefined) {
          json.includeTaxAmount2 = '0';
        }
        if (json.totalApplyAmount != Number(json.includeTaxAmount1) + Number(json.includeTaxAmount2)) {
          this.$notify({
            title: '警告',
            message: '总申请金额与含税金额之和不相符，请重新录入',
            type: 'warning'
          });
          return;
        }
        if (json.totalApplyAmountD !== undefined && json.totalApplyAmountD !== null) {
          if (json.includeTaxAmount2D === undefined) {
            json.includeTaxAmount2D = '0';
          }
          if (json.totalApplyAmountD != Number(json.includeTaxAmount1D) + Number(json.includeTaxAmount2D)) {
            this.$notify({
              title: '警告',
              message: '第二项总申请金额与含税金额之和不相符，请重新录入',
              type: 'warning'
            });
            return;
          }
          if (this.rowData.id) {
            console.log(this.totalApplyAmountDR);
            if (this.totalApplyAmountDR == null) {
              this.totalApplyAmountDR = 0;
            }
            if (json.totalApplyAmountD > json.totalAmountD + this.totalApplyAmountDR) {
              this.$notify({
                title: '警告',
                message: '第二项总申请金额不能大于返利可用余额',
                type: 'warning'
              });
              return;
            }
          } else {
            if (json.totalApplyAmountD > json.totalAmountD) {
              this.$notify({
                title: '警告',
                message: '第二项总申请金额不能大于返利可用余额',
                type: 'warning'
              });
              return;
            }
          }
        }
        if (!json.rebateTypeD) {
          json.totalApplyAmountD = null;
          json.taxRate1D = null;
          json.includeTaxAmount1D = null;
          json.includeTaxAmount2D = null;
          json.outcluedeTaxAmount1D = null;
          json.outcluedeTaxAmount2D = null;
          json.taxAmount1D = null;
          json.taxAmount2D = null;
          json.taxRate2D = null;
        }
        let res = await saveData(json);
        if (res.resultCode == 200) {
          if (type == 60211001) {
            this.$notify({
              title: '成功',
              message: '保存成功',
              type: 'success'
            });
          } else {
            this.$notify({
              title: '成功',
              message: '提报成功',
              type: 'success'
            });
          }

          this.closeDrawer('refresh');
        }
      }
    },
    closeDrawer(type) {
      this.$emit('close', false, type);
    },
    // 公司代码
    changeCompany(val) {
      this.formList.find(x => x.fieldName == 'salesOrgCode').initialValue = '';
      this.formList.find(x => x.fieldName == 'salesOrgCode').itemList = [];
      if (val == 60081001) {
        this.formList.find(x => x.fieldName == 'salesOrgCode').itemList = [{ text: '北京蓝谷极狐投资管理有限公司销售组织', value: '1012' }];
      }
      if (val == 60081002) {
        this.formList.find(x => x.fieldName == 'salesOrgCode').itemList = [
          { text: '北京新能源汽车营销有限公司', value: '2000' },
          { text: '青岛卫蓝销售公司', value: '2001' }
        ];
      }
    },
    async getAmount(powerType, rebateType, dealerCode) {
      if (!powerType || !rebateType || !dealerCode) {
        return;
      } else {
        let res = await getAmount({ powerType: powerType, rebateType: rebateType, dealerCode: dealerCode });
        this.formList.find(x => x.fieldName == 'totalAmount').initialValue = res.data;
      }
    },
    async getAmountD(powerType, rebateType, dealerCode) {
      if (!powerType || !rebateType || !dealerCode) {
        return;
      } else {
        let res = await getAmount({ powerType: powerType, rebateType: rebateType, dealerCode: dealerCode });
        this.formList.find(x => x.fieldName == 'totalAmountD').initialValue = res.data;
      }
    },
    createdFrom() {
      return [
        {
          type: 'INPUT',
          label: '申请单号',
          fieldName: 'applyNo',
          placeholder: '系统自动生成',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '经销商代码',
          fieldName: 'dealerCode',
          placeholder: '',
          readonly: true,
          rules: [{ required: true, message: '请选择经销商', trigger: 'change' }],
          unitRender: () => {
            return <el-button slot="append" icon="el-icon-search" onClick={this.dealerHandle}></el-button>;
          }
        },
        {
          type: 'INPUT',
          label: '经销商名称',
          fieldName: 'dealerName',
          placeholder: '请输入',
          rules: [{ required: true, message: '请选择经销商', trigger: 'change' }],
          disabled: true
        },
        {
          type: 'SELECT',
          label: '动力形式',
          fieldName: 'powerType',
          placeholder: '请选择',
          itemList: this.createDictList('6008'),
          initialValue: 60081002,
          disabled: true,
          offsetRightCols: 2,
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
          change: val => {
            ;
            // this.changeCompany(val)
            if (val) {
              let powerType = val;
              let rebateType = this.formList.find(x => x.fieldName == 'rebateType').initialValue;
              let dealerCode = this.formList.find(x => x.fieldName == 'dealerCode').initialValue;
              this.getAmount(powerType, rebateType, dealerCode);
              this.getSalesOrgCode(val);
              if (getAppId() == 'beijing') {
                  this.formList.find(x => x.fieldName == 'rebateType').initialValue = "";
                  this.formList.find(x => x.fieldName == 'rebateTypeD').initialValue = "";
                if (val == 60081001) {
                  this.formList.find(x => x.fieldName == 'rebateType').itemList = this.createDictList('6036', [60361002]);
                  this.formList.find(x => x.fieldName == 'rebateTypeD').itemList = this.createDictList('6036', [60361002]);
                } else {
                  this.formList.find(x => x.fieldName == 'rebateType').itemList = this.createDictList('6036');
                  this.formList.find(x => x.fieldName == 'rebateTypeD').itemList = this.createDictList('6036');
                }
              }
              return;
            }
            this.formList.find(x => x.fieldName == 'salesOrgCode').initialValue = '';
            this.formList.find(x => x.fieldName == 'salesOrgCode').itemList = [];
          }
        },
        {
          type: 'SELECT',
          label: '公司代码',
          fieldName: 'salesOrgCode',
          placeholder: '请输入',
          itemList: [],
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
          change: p => {}
        },
        {
          type: 'DATE',
          label: '申请时间',
          fieldName: 'applyDate',
          // dateType: 'exactdate',
          placeholder: '请输入',
          initialValue: moment().format('YYYY-MM-DD HH:mm:ss')
        },

        {
          type: 'INPUT',
          label: '申请人',
          fieldName: 'applyPersonName',
          placeholder: '自动带出',
          initialValue: getUser(),
          disabled: true
        },
        {
          type: 'INPUT',
          label: '总申请金额',
          fieldName: 'totalApplyAmount',
          placeholder: '请输入',
          disabled: true,
          rules: [{ required: true, message: '请输入', trigger: 'blur' }],
          offsetRightCols: 2,
          change: val => {
            if (!this.formList.find(x => x.fieldName == 'includeTaxAmount1').initialValue && !this.formList.find(x => x.fieldName == 'includeTaxAmount2').initialValue) {
              this.formList.find(x => x.fieldName == 'includeTaxAmount1').initialValue = parseFloat(val);
              this.taxRate1 = parseFloat(this.formList.find(x => x.fieldName == 'taxRate1').initialValue);
              this.Amount1 = parseFloat(val);
              this.taxAmount1;
              // this.formList.find(x => x.fieldName == 'includeTaxAmount2').initialValue = parseFloat(val);
              // this.taxRate2 = parseFloat(this.formList.find(x => x.fieldName == 'taxRate2').initialValue);
              // this.Amount2 = parseFloat(val);
              // this.taxAmount2;
            }
          }
        },
        {
          type: 'SELECT',
          label: '返利类型',
          fieldName: 'rebateType',
          placeholder: '请选择',
          initialValue: '',
          itemList: this.createDictList('6036'),
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
          change: val => {
            let powerType = this.formList.find(x => x.fieldName == 'powerType').initialValue;
            let rebateType = val;
            let dealerCode = this.formList.find(x => x.fieldName == 'dealerCode').initialValue;
            this.getAmount(powerType, rebateType, dealerCode);
            let array = [];
            array.push(val);
            if (getAppId() == 'beijing') {
              array.push(val);
              if(powerType==60081001){
                array.push(60361002)
              }
            }
            if(val){
              this.formList.find(x => x.fieldName == 'rebateTypeD').itemList = this.createDictList('6036', array);
            }else{
              this.formList.find(x => x.fieldName == 'rebateTypeD').itemList = this.createDictList('6036');
            }
            
          }
        },
        {
          type: 'INPUT',
          label: '返利可用余额',
          fieldName: 'totalAmount',
          placeholder: '',
          offsetRightCols: 1,
          disabled: true,
          rules: [{ required: true, message: '请选择', trigger: 'blur' }]
        },
        {
          type: 'INPUT_NUMBER',
          label: '税率1（%）',
          min: 0,
          max: 999999999,
          precision: 2,
          fieldName: 'taxRate1',
          placeholder: '请输入',
          initialValue: 13,
          rules: [{ required: true, message: '请选择', trigger: 'blur' }],
          change: val => {
            this.taxRate1 = parseFloat(val) || 0;
            this.Amount1 = parseFloat(this.formList.find(x => x.fieldName == 'includeTaxAmount1').initialValue) || 0;
            this.taxAmount1;
          }
        },
        {
          type: 'INPUT_NUMBER',
          label: '金额1（含税）',
          fieldName: 'includeTaxAmount1',
          placeholder: '请输入',
          min: 0,
          max: 999999999,
          precision: 2,
          rules: [{ required: true, message: '请选择', trigger: 'blur' }],
          change: val => {
            this.Amount1 = parseFloat(val) || 0;
            this.taxRate1 = parseFloat(this.formList.find(x => x.fieldName == 'taxRate1').initialValue) || 0;
            this.taxAmount1;
            if (!val) {
              val = 0;
            }
            this.formList.find(x => x.fieldName == 'totalApplyAmount').initialValue = parseFloat(val) + this.Amount2;
          }
        },
        {
          type: 'INPUT',
          label: '税额1',
          fieldName: 'taxAmount1',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '不含税金额1',
          fieldName: 'outcluedeTaxAmount1',
          placeholder: '',
          disabled: true,
          offsetRightCols: 2
        },

        {
          type: 'INPUT_NUMBER',
          label: '税率2（%）',
          fieldName: 'taxRate2',
          min: 0,
          max: 999999999,
          precision: 2,
          placeholder: '请输入',
          initialValue: '',
          rules: [],
          change: val => {
            this.taxRate2 = parseFloat(val) || 0;
            this.Amount2 = parseFloat(this.formList.find(x => x.fieldName == 'includeTaxAmount2').initialValue) || 0;
            this.taxAmount2;
          }
        },
        {
          type: 'INPUT_NUMBER',
          label: '金额2（含税）',
          fieldName: 'includeTaxAmount2',
          placeholder: '请输入',
          min: 0,
          max: 999999999,
          precision: 2,
          change: val => {
            // let totalAmount = this.formList.find(x => x.fieldName == 'totalApplyAmount').initialValue || 0;
            // let Amount1 = totalAmount > 0 ? parseFloat(totalAmount) - parseFloat(val) : 0;
            // this.formList.find(x => x.fieldName == 'includeTaxAmount1').initialValue = parseFloat(Amount1);
            // this.taxRate1 = parseFloat(this.formList.find(x => x.fieldName == 'taxRate1').initialValue) || 0;
            // this.Amount1 = parseFloat(this.formList.find(x => x.fieldName == 'includeTaxAmount1').initialValue) || 0;
            // this.taxAmount1;
            this.Amount2 = parseFloat(val) || 0;
            this.taxRate2 = parseFloat(this.formList.find(x => x.fieldName == 'taxRate2').initialValue) || 0;
            this.taxAmount2;
            if (val) {
              this.formList.find(x => x.fieldName == 'taxRate2').rules = [{ required: true, message: '请输入', trigger: 'blur' }];
            } else {
              val = 0;
              this.formList.find(x => x.fieldName == 'taxRate2').rules = [{ required: false, message: '请输入', trigger: 'blur' }];
            }
            this.formList.find(x => x.fieldName == 'totalApplyAmount').initialValue = parseFloat(val) + this.Amount1;
          }
        },
        {
          type: 'INPUT',
          label: '税额2',
          fieldName: 'taxAmount2',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '不含税金额2',
          fieldName: 'outcluedeTaxAmount2',
          placeholder: '',
          disabled: true,
          offsetRightCols: 2
        },
        {
          type: 'BREAK_SPACE',
          label: ''
        },
        {
          type: 'INPUT',
          label: '总申请金额',
          fieldName: 'totalApplyAmountD',
          placeholder: '请输入',
          disabled: true,
          offsetRightCols: 2,
          rules: [],
          change: val => {
            if (!this.formList.find(x => x.fieldName == 'includeTaxAmount1D').initialValue && !this.formList.find(x => x.fieldName == 'includeTaxAmount2D').initialValue) {
              this.formList.find(x => x.fieldName == 'includeTaxAmount1D').initialValue = parseFloat(val);
              this.taxRate1D = parseFloat(this.formList.find(x => x.fieldName == 'taxRate1D').initialValue);
              this.Amount1D = parseFloat(val);
              this.taxAmount1D;
              this.formList.find(x => x.fieldName == 'includeTaxAmount1D');
            }
          }
        },
        // {
        //   type: 'SELECT',
        //   label: '动力形式',
        //   fieldName: 'powerTypeD',
        //   placeholder: '请选择',
        //   itemList: this.createDictList('6008'),
        //   initialValue: 60081002,
        //   rules: [],
        //   disabled: true,
        //   change: val => {
        //     // this.changeCompany(val)
        //     if (val) {
        //       let powerTypeD = val;
        //       let rebateTypeD = this.formList.find(x => x.fieldName == 'rebateTypeD').initialValue;
        //       let dealerCode = this.formList.find(x => x.fieldName == 'dealerCode').initialValue;
        //       this.getAmountD(powerTypeD, rebateTypeD, dealerCode);
        //       this.getSalesOrgCode(val);
        //       return;
        //     }
        //     this.formList.find(x => x.fieldName == 'salesOrgCode').initialValue = '';
        //     this.formList.find(x => x.fieldName == 'salesOrgCode').itemList = [];
        //   }
        // },
        {
          type: 'SELECT',
          label: '返利类型',
          fieldName: 'rebateTypeD',
          placeholder: '请选择',
          itemList: this.createDictList('6036'),
          change: val => {
            let powerType = this.formList.find(x => x.fieldName == 'powerType').initialValue;
            let rebateTypeD = val;
            let dealerCode = this.formList.find(x => x.fieldName == 'dealerCode').initialValue;
            this.getAmountD(powerType, rebateTypeD, dealerCode);
            if (val) {
              let array = [];
              array.push(val);
              if (getAppId() == 'beijing') {
                array.push(val);
                if(powerType==60081001){
                  array.push(60361002)
                }
              }
              this.formList.find(x => x.fieldName == 'rebateType').itemList = this.createDictList('6036', array);
              this.formList.find(x => x.fieldName == 'totalApplyAmountD').rules = [{ required: true, message: '请输入', trigger: 'blur' }];
              this.formList.find(x => x.fieldName == 'totalAmountD').rules = [{ required: true, message: '请输入', trigger: 'blur' }];
              this.formList.find(x => x.fieldName == 'taxRate1D').rules = [{ required: true, message: '请输入', trigger: 'blur' }];
              this.formList.find(x => x.fieldName == 'includeTaxAmount1D').rules = [{ required: true, message: '请输入', trigger: 'blur' }];
            } else {
              this.formList.find(x => x.fieldName == 'totalApplyAmountD').rules = [{ required: false, message: '请输入', trigger: 'blur' }];
              this.formList.find(x => x.fieldName == 'totalAmountD').rules = [{ required: false, message: '请输入', trigger: 'blur' }];
              this.formList.find(x => x.fieldName == 'taxRate1D').rules = [{ required: false, message: '请输入', trigger: 'blur' }];
              this.formList.find(x => x.fieldName == 'includeTaxAmount1D').rules = [{ required: false, message: '请输入', trigger: 'blur' }];
              this.formList.find(x => x.fieldName == 'totalApplyAmountD').initialValue = '';
              this.formList.find(x => x.fieldName == 'totalAmountD').initialValue = '';
              this.formList.find(x => x.fieldName == 'taxRate1D').initialValue = '';
              this.formList.find(x => x.fieldName == 'includeTaxAmount1D').initialValue = '';
              this.formList.find(x => x.fieldName == 'taxAmount1D').initialValue = '';
              this.formList.find(x => x.fieldName == 'outcluedeTaxAmount1D').initialValue = '';
              this.formList.find(x => x.fieldName == 'taxRate2D').initialValue = '';
              this.formList.find(x => x.fieldName == 'includeTaxAmount2D').initialValue = '';
              this.formList.find(x => x.fieldName == 'taxAmount2D').initialValue = '';
              this.formList.find(x => x.fieldName == 'outcluedeTaxAmount2D').initialValue = '';
              this.formList.find(x => x.fieldName == 'rebateType').itemList = this.createDictList('6036');
            }
          }
        },
        {
          type: 'INPUT',
          label: '返利可用余额',
          fieldName: 'totalAmountD',
          placeholder: '',
          rules: [],
          offsetRightCols: 1,
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          label: '税率1（%）',
          fieldName: 'taxRate1D',
          placeholder: '请输入',
          rules: [],
          min: 0,
          max: 999999999,
          precision: 2,
          initialValue: 13,
          change: val => {
            this.taxRate1D = parseFloat(val) || 0;
            this.Amount1D = parseFloat(this.formList.find(x => x.fieldName == 'includeTaxAmount1D').initialValue) || 0;
            this.taxAmount1D;
          }
        },
        {
          type: 'INPUT_NUMBER',
          label: '金额1（含税）',
          fieldName: 'includeTaxAmount1D',
          placeholder: '请输入',
          rules: [],
          min: 0,
          max: 999999999,
          precision: 2,
          change: val => {
            this.Amount1D = parseFloat(val);
            this.taxRate1D = parseFloat(this.formList.find(x => x.fieldName == 'taxRate1D').initialValue) || 0;
            this.taxAmount1D;
            if (!val) {
              val = 0;
            }
            this.formList.find(x => x.fieldName == 'totalApplyAmountD').initialValue = parseFloat(val) + this.Amount2D;
          }
        },
        {
          type: 'INPUT',
          label: '税额1',
          fieldName: 'taxAmount1D',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '不含税金额1',
          fieldName: 'outcluedeTaxAmount1D',
          placeholder: '',
          disabled: true,
          offsetRightCols: 2
        },

        {
          type: 'INPUT_NUMBER',
          label: '税率2（%）',
          fieldName: 'taxRate2D',
          placeholder: '请输入',
          min: 0,
          max: 999999999,
          precision: 2,
          rules: [],
          initialValue: '',
          change: val => {
            this.taxRate2D = parseFloat(val) || 0;
            this.Amount2D = parseFloat(this.formList.find(x => x.fieldName == 'includeTaxAmount2D').initialValue) || 0;
            this.taxAmount2D;
          }
        },
        {
          type: 'INPUT_NUMBER',
          label: '金额2（含税）',
          fieldName: 'includeTaxAmount2D',
          placeholder: '请输入',
          min: 0,
          max: 999999999,
          precision: 2,
          change: val => {
            // let totalAmount = this.formList.find(x => x.fieldName == 'totalApplyAmount').initialValue || 0;
            // let Amount1 = totalAmount > 0 ? parseFloat(totalAmount) - parseFloat(val) : 0;
            // this.formList.find(x => x.fieldName == 'includeTaxAmount1').initialValue = parseFloat(Amount1);
            // this.taxRate1 = parseFloat(this.formList.find(x => x.fieldName == 'taxRate1').initialValue) || 0;
            // this.Amount1 = parseFloat(this.formList.find(x => x.fieldName == 'includeTaxAmount1').initialValue) || 0;
            // this.taxAmount1;

            this.Amount2D = parseFloat(val) || 0;
            this.taxRate2D = parseFloat(this.formList.find(x => x.fieldName == 'taxRate2D').initialValue) || 0;
            this.taxAmount2D;
            if (val) {
              this.formList.find(x => x.fieldName == 'taxRate2D').rules = [{ required: true, message: '请输入', trigger: 'blur' }];
            } else {
              val = 0;
              this.formList.find(x => x.fieldName == 'taxRate2D').rules = [{ required: false, message: '请输入', trigger: 'blur' }];
            }
            this.formList.find(x => x.fieldName == 'totalApplyAmountD').initialValue = parseFloat(val) + this.Amount1D;
          }
        },
        {
          type: 'INPUT',
          label: '税额2',
          fieldName: 'taxAmount2D',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '不含税金额2',
          fieldName: 'outcluedeTaxAmount2D',
          placeholder: '',
          disabled: true,
          offsetRightCols: 2
        },
        {
          type: 'BREAK_SPACE',
          label: ''
        },
        {
          type: 'INPUT',
          label: '红字发票信息表编号',
          fieldName: 'remark',
          selfCols: 3,
          placeholder: '请输入',
          rules: [{ required: true, message: '请输入', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '审批意见',
          fieldName: 'checkDesc',
          selfCols: 3,
          placeholder: '请输入',
          disabled: true
        }
      ];
    }
  }
};
</script>
